var _display_all_categries = 0;
var _hover_div;
function display_hover( action,showing_div_id )
{				
	_display_all_categries = action;
	_hover_div = $( showing_div_id );
	if( action ){	
		if( _hover_div )
			_hover_div.style.display = '';
				
	}else{
		setTimeout("hide_hover()",1000);
	}
}


function hide_hover()
{
	if( _display_all_categries == 0 )
		if( _hover_div )
			_hover_div.style.display = 'none';	
	
}

function uncoverable_elements_visible( flag )
{
	/*
	var visible = flag?'':"hidden";
	if( (document.all && !window.opera) ){
		var els = document.getElementsByTagName('select');
		for (var i = 0; i < els.length; i++) {
			els[ i ].style.visibility = visible;
		}
	}
	*/
	if( (document.all && !window.opera) ){
		items = $$('#currency ul', '.truncated_full_value .item-options', '.tool-tip');
		for (var j=0; j<items.length; j++) {
			iframe = document.createElement('IFRAME');
			iframe.src = BLANK_URL;
			iframe.scrolling = 'no';
			iframe.frameBorder = 0;
			iframe.className = 'hover-fix';
			iframe.style.width = items[j].offsetWidth+"px";
			iframe.style.height = items[j].offsetHeight+"px";
			items[j].insertBefore(iframe, items[j].firstChild);
		}
	}
}

function price_range_url( base_url )
{
	var range,index;
	if( $('price_start_filter').value > 0 && $('price_end_filter').value > 0 && $('price_end_filter').value > $('price_start_filter').value ){
		range = $('price_end_filter').value - $('price_start_filter').value;
		index = $('price_end_filter').value/range;
		setLocation( base_url + 'price=' + index + '%2C' + range );
	}else{
		$('price_start_filter').style.border = "red 1px solid";
		$('price_end_filter').style.border = "red 1px solid";
	}
}

DD_roundies.addRule('.js_corner_3', '3px', true);
DD_roundies.addRule('.js_corner_4', '4px', true);
DD_roundies.addRule('.js_corner_5', '5px', true);
DD_roundies.addRule('.js_corner_6', '6px', true);
DD_roundies.addRule('.js_corner_7', '7px', true);
DD_roundies.addRule('.js_corner_8', '8px', true);
DD_roundies.addRule('.js_corner_9', '9px', true);
DD_roundies.addRule('.js_corner_10', '10px', true);
DD_roundies.addRule('.js_corner_11', '11px', true);
DD_roundies.addRule('.js_corner_12', '12px', true);
DD_roundies.addRule('.js_corner_13', '13px', true);
DD_roundies.addRule('.js_corner_14', '14px', true);
DD_roundies.addRule('.js_corner_15', '15px', true);
DD_roundies.addRule('.js_corner_16', '16px', true);
DD_roundies.addRule('.js_corner_17', '17px', true);
DD_roundies.addRule('.js_corner_18', '18px', true);
DD_roundies.addRule('.js_corner_19', '19px', true);
DD_roundies.addRule('.js_corner_20', '20px', true);

DD_roundies.addRule('.js_corner_t_6', '6px 6px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_7', '7px 7px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_8', '8px 8px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_9', '9px 9px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_10', '10px 10px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_11', '11px 11px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_12', '12px 12px 0px 0px', true);
DD_roundies.addRule('.js_corner_t_13', '13px 13px 0px 0px', true);

DD_roundies.addRule('.js_corner_b_6', '0px 0px 6px 6px', true);
DD_roundies.addRule('.js_corner_b_7', '0px 0px 7px 7px', true);
DD_roundies.addRule('.js_corner_b_8', '0px 0px 8px 8px', true);
DD_roundies.addRule('.js_corner_b_9', '0px 0px 9px 9px', true);
DD_roundies.addRule('.js_corner_b_10', '0px 0px 10px 10px', true);
DD_roundies.addRule('.js_corner_b_11', '0px 0px 11px 11px', true);
DD_roundies.addRule('.js_corner_b_12', '0px 0px 12px 12px', true);
DD_roundies.addRule('.js_corner_b_13', '0px 0px 13px 13px', true);
/*
DD_roundies.addRule('.button', '4px', true);
DD_roundies.addRule('.main', '8px', true);
DD_roundies.addRule('.block-title', '6px 6px 0px 0px', true);
DD_roundies.addRule('.col-main', '8px', true);
*/

function make_offer( product_id,url )
{
	if( product_id > 0 ){ //single mode
		var qty = $("offer_qty_"+product_id).value;
		var price = $("offer_price_"+product_id).value;
		if( qty > 0 && price > 0 ){
			if( url == '' )
				alert("warnning:url empty");
				setLocation( url + "?product_id="+product_id+"&offer_price="+price+"&offer_qty="+qty );
		}else{
			if( qty > 0 ){
				$("offer_price_"+product_id).focus();
			}else{
				$("offer_qty_"+product_id).focus();
			}
		}			
	}else{
		document.multiple_products_make_offer.submit();
	}//list mode.
	return false;
}

function str_replace (search, replace, subject, count) 
{   
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}


function stristr( haystack, needle, bool ) 
{
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfxied by: Onno Marsman
    // *     example 1: stristr('Kevin van Zonneveld', 'Van');
    // *     returns 1: 'van Zonneveld'
    // *     example 2: stristr('Kevin van Zonneveld', 'VAN', true);
    // *     returns 2: 'Kevin '
 
    var pos = 0;
 
    haystack += '';
    pos = haystack.toLowerCase().indexOf( (needle+'').toLowerCase() );
    if( pos == -1 ){
        return false;
    } else{
        if( bool ){
            return haystack.substr( 0, pos );
        } else{
            return haystack.slice( pos );
        }
    }
}

var auto_height = {};

auto_height.getElementsByName = function (tag,eltname){ 
	var elts=document.getElementsByTagName(tag); 
	var count=0; 
	var elements=[]; 
	for(var i=0;i<elts.length;i++){ 
		if(elts[i].getAttribute("name")==eltname){ 
			elements[count++]=elts[i];
		} 
	}
	return elements; 
} 

auto_height.getElementsByClass = function (tag,className){ 
	var elts=document.getElementsByTagName(tag); 
	var count=0; 
	var elements=[]; 
	
	for(var i=0;i<elts.length;i++){ 
		
		if( stristr( elts[i].className,className ) ){ 
			
			elements[count++]=elts[i];
		} 
	}
	return elements; 
} 

auto_height.maxHeight = function ( tag,name ){
	var els = auto_height.getElementsByName(tag, name);
	var h = "";
	for (var i=0;i<els.length;i++){
		h += els[i].clientHeight + ",";
	}
	h = h.slice(0, -1);
	h = eval('Math.max('+h+')');
	
	return h;
}	

auto_height.maxHeightElement = function ( tags ){
	
	var h = "";
	for (var i=0;i<tags.length;i++){
		
		h += tags[i].clientHeight + ",";
	}
	h = h.slice(0, -1);
	h = eval('Math.max('+h+')');
	
	var h_offset = auto_height.maxHeightElementOffsetHeight( tags );
	var h_scroll = auto_height.maxHeightElementScrollHeight( tags );
	
	//alert( h+','+h_offset+','+h_scroll );
	
	return eval('Math.max('+h+','+h_offset+','+h_scroll+')');
}	

auto_height.maxHeightElementV2 = function ( tags ){
	
	var h = "";
	for (var i=0;i<tags.length;i++){
		
		h += tags[i].scrollHeight + ",";
	}
	h = h.slice(0, -1);
	return eval('Math.max('+h+')');
	
	//var h_offset = auto_height.maxHeightElementOffsetHeight( tags );
	//var h_scroll = auto_height.maxHeightElementScrollHeight( tags );
	
	//alert( h+','+h_offset+','+h_scroll );
	
	//return eval('Math.min('+h+','+h_offset+','+h_scroll+')');
}	


auto_height.maxHeightElementOffsetHeight = function ( tags ){
	
	var h = "";
	for (var i=0;i<tags.length;i++){
		
		h += tags[i].offsetHeight + ",";
	}
	h = h.slice(0, -1);
	h = eval('Math.max('+h+')');
	
	return h;
}	

auto_height.maxHeightElementScrollHeight = function ( tags ){
	
	var h = "";
	for (var i=0;i<tags.length;i++){
		
		h += tags[i].scrollHeight + ",";
	}
	h = h.slice(0, -1);
	h = eval('Math.max('+h+')');
	
	return h;
}	

auto_height.sameHeight = function (tag, name,h){
	var els = auto_height.getElementsByClass(tag, name);
	
	if( !(h>0) ){
		var calculate_h = 1;
	}else var calculate_h = 0;
	
	for (var j=0;j<els.length;j+=3){
		
		var tagset = new Array( els[j] );
		if( calculate_h ){
			if( els[j+1] && els[j+2] ){
				var tagset = new Array( els[j],els[j+1],els[j+2] );
			}else if( els[j+1] ){
				var tagset = new Array( els[j],els[j+1] );
			}
			h = auto_height.maxHeightElement( tagset );
			
		}
		
		if( els[j] ){
			els[j].style.height = h+'px';
		}
		if( els[j+1] ){
			els[j+1].style.height = h+'px';
		}
		if( els[j+2] ){
			els[j+2].style.height = h+'px';
		}
		
	}
	
}

auto_height.sameHeight4Col = function (tag, name,h){
	var els = auto_height.getElementsByClass(tag, name);
	
	if( !(h>0) ){
		var calculate_h = 1;
	}else var calculate_h = 0;
	
	for (var j=0;j<els.length;j+=4){
		
		var tagset = new Array( els[j] );
		if( calculate_h ){
			if( els[j+1] && els[j+2] && els[j+3] ){
				var tagset = new Array( els[j],els[j+1],els[j+2],els[j+3] );
			}else if( els[j+1] && els[j+2] ){
				var tagset = new Array( els[j],els[j+1],els[j+2] );
			}else if( els[j+1] ){
				var tagset = new Array( els[j],els[j+1] );
			}
			h = auto_height.maxHeightElement( tagset );
			
		}
		
		if( els[j] ){
			els[j].style.height = h+'px';
		}
		if( els[j+1] ){
			els[j+1].style.height = h+'px';
		}
		if( els[j+2] ){
			els[j+2].style.height = h+'px';
		}
		if( els[j+3] ){
			els[j+3].style.height = h+'px';
		}
		
	}
	
}

auto_height.sameHeight5Col = function (tag, name,h){
	var els = auto_height.getElementsByClass(tag, name);
	
	if( !(h>0) ){
		var calculate_h = 1;
	}else var calculate_h = 0;
	
	for (var j=0;j<els.length;j+=5){
		
		var tagset = new Array( els[j] );
		if( calculate_h ){
			if( els[j+1] && els[j+2] && els[j+3] && els[j+4] ){
				var tagset = new Array( els[j],els[j+1],els[j+2],els[j+3],els[j+4] );
			}else if( els[j+1] && els[j+2] && els[j+3] ){
				var tagset = new Array( els[j],els[j+1],els[j+2],els[j+3] );
			}else if( els[j+1] && els[j+2] ){
				var tagset = new Array( els[j],els[j+1],els[j+2] );
			}else if( els[j+1] ){
				var tagset = new Array( els[j],els[j+1] );
			}
			h = auto_height.maxHeightElement( tagset );
			
		}
		
		if( els[j] ){
			els[j].style.height = h+'px';
		}
		if( els[j+1] ){
			els[j+1].style.height = h+'px';
		}
		if( els[j+2] ){
			els[j+2].style.height = h+'px';
		}
		if( els[j+3] ){
			els[j+3].style.height = h+'px';
		}
		if( els[j+4] ){
			els[j+4].style.height = h+'px';
		}
		
	}
	
}

auto_height.sameHeight2ColRight = function (tag, name,h){
	var els = auto_height.getElementsByClass(tag, name);
	
	if( !(h>0) ){
		var calculate_h = 1;
	}else var calculate_h = 0;
	
	for (var j=0;j<els.length;j+=2){
		
		var tagset = new Array( els[j] );
		if( calculate_h ){
			if( els[j+1] ){
				var tagset = new Array( els[j],els[j+1] );
			}
			h = auto_height.maxHeightElement( tagset );
			
		}
		
		if( els[j] && els[j+1]){			
			els[j].style.height = h+'px';		
			els[j+1].style.height = h+'px';
		}
		
		
	}
	
}



auto_height.clearHeight = function (tag, name,h){
	var els = auto_height.getElementsByClass(tag, name);
	
	for (var j=0;j<els.length;j+=3){
		els[j].style.height = '';
	}
}